Improve the output of the debugger#4365
Conversation
…bugger, changed the input line indicates we are in the debugger from iine to <M2 Debugger>, and we added carets below the specific characters causing an error.
…function code'', adds carets for single line errors, and adds carets on first and last characters for multiple line outputs.
…Currently, this is not changeable by the user. We, also cleaned up the code.
…hich are available to the function code.
| code Function := opt -> f -> codeFunction(null, f, 0) | ||
| code Command := opt -> C -> code C#0 | ||
| code List := opt -> L -> DIV between_(HR{}) dedupMethods apply(L, code) | ||
| code ZZ := opt -> i -> code previousMethodsFound#i |
There was a problem hiding this comment.
| code ZZ := opt -> i -> code previousMethodsFound#i | |
| code ZZ := opt -> i -> code(previousMethodsFound#i, opt) |
code(TestInput) in testing.m2 also needs updated to use options
There was a problem hiding this comment.
Ah I'm afraid this is going to mess up code for hooks, e.g.:
i3 : code(syz, Matrix, Strategy => Default)
o3 = -- code for strategy: syz(Matrix,Strategy => Default)
../linuxbrew/.linuxbrew/Cellar/macaulay2/1.26.05/share/Macaulay2/Core/
matrix2.m2:315:44-321:6: --source code:
addHook((syz, Matrix), Strategy => Default, (opts, f) -> (
if not isFreeModule target f or not isFreeModule source f
then error "expected map between free modules";
if ring f === ZZ or not isHomogeneous f
then syz gb (f, opts, Syzygies=>true)
else mingens image syz gb (f, opts, Syzygies=>true)
))There was a problem hiding this comment.
That's going to be a hard issue to fix cleanly, given this issue, I'm leaning towards just using the global to control the formating. It's a bit unfortunate, because the downside of the new output is it's hard to copy paste.
|
|
||
|
|
||
| protect PrintCaret | ||
| protect PrintLineNum |
There was a problem hiding this comment.
I'm wondering if we should export these, too, so users can pass them to code? If so, then I'd considering using PrintCarets and PrintLineNumbers to match the corresponding debug-prefixed global variables.
We'd also need to update the code docs accordingly.
| @@ -0,0 +1,29 @@ | |||
|
|
|||
There was a problem hiding this comment.
Was adding this file just a git oopsie?
| file = lines file; | ||
| if #file < stop then error("line number ",toString stop, " not found in file ", filename); | ||
| DIV splice { codeAddress(x), codeContent(start, stop, file) } | ||
| DIV splice { codeAddress(x), codeContent(PrintCaret => debugPrintCarets, PrintLineNum => debugPrintLineNumbers, x, start, stop, file) } |
There was a problem hiding this comment.
It seems like we should use opt here. Maybe the default values should be null, and if so, use the global variables?
Either that or just drop options entirely and use the global variables inside codeContent?
|
@jkyang92 Yes I am ok with the work being distributed under GPL2+ |
| -- ZZ#{Standard,InputPrompt} = lineno -> concatenate(newline, lastprompt = concatenate(interpreterDepth:"i", toString lineno, " : ")); | ||
|
|
||
| ZZ#{Standard,InputPrompt} = lineno -> concatenate(newline, lastprompt = if (interpreterDepth == 1) then concatenate(interpreterDepth:"i", toString lineno, " : ") else concatenate("<M2 Debugger> ", interpreterDepth:"i", toString lineno, " : ")); | ||
| -- if interpreterDepth > 0 then ( | ||
| -- ZZ#{Standard,InputPrompt} = lineno -> concatenate("<M2 Debugger> ",lastprompt); | ||
| -- ); |
There was a problem hiding this comment.
Could we make the prompt a little shorter? Maybe just <debugger> iiNN : for instance?
Also the commented lines should be removed.
| -- ZZ#{Standard,InputPrompt} = lineno -> concatenate(newline, lastprompt = concatenate(interpreterDepth:"i", toString lineno, " : ")); | |
| ZZ#{Standard,InputPrompt} = lineno -> concatenate(newline, lastprompt = if (interpreterDepth == 1) then concatenate(interpreterDepth:"i", toString lineno, " : ") else concatenate("<M2 Debugger> ", interpreterDepth:"i", toString lineno, " : ")); | |
| -- if interpreterDepth > 0 then ( | |
| -- ZZ#{Standard,InputPrompt} = lineno -> concatenate("<M2 Debugger> ",lastprompt); | |
| -- ); | |
| ZZ#{Standard,InputPrompt} = lineno -> concatenate(newline, | |
| lastprompt = concatenate(if interpreterDepth == 1 then "<debugger> ", interpreterDepth:"i", toString lineno, " : "); |
| oldDebuggerCode := getGlobalVariable(currentS); | ||
| setGlobalVariable(currentS,Expr(PseudocodeClosure(f,c))); | ||
| printMessage(codePosition(c), "entering debugger (enter 'help' to see commands)"); | ||
| printMessage(codePosition(c), "\n"+ "ENTERING DEBUGGER (enter 'help' to see commands, enter 'break' to quit the debugger)"); |
There was a problem hiding this comment.
Is it possible to make this print only once?
There was a problem hiding this comment.
+1
I remember being surprised by this at the demo in Atlanta
| "However, the following attempt results in an error, and the debugger starts up automatically.", | ||
| EXAMPLE "g 2", | ||
| "You may use ", TO "help", ", as instructed, to view the commands available in the debugger. | ||
| "Here it says ENTERING DEBUGGER when you enter the deugger. You may use ", TO "help", ", as instructed, to view the commands available in the debugger. |
This is a draft pull request improving the output of the current line of code in the debugger.
This pull request contains work with @adamlaclair @BrysonKagy @OlaPeteru from the Building the Future of Macaualy2 workshop. Comments welcome, I will still read through this to make sure that nothing is missing and no obvious issues remain.
These commits do not include any AI generated code.
@adamlaclair @BrysonKagy, Can you respond verifying that that the code from your commits can be distributed under GPL2+? (or the public domain or other compatible license if that is not acceptable)